// WARNING: This file has been generated. Any manual changes must be made within preserved regions or they will be lost.

//===============================================================================
//
// AuditDateColumnCollection
//
// PURPOSE: 
// 
//
// NOTES: 
// 
//
//===============================================================================
//
// Copyright (C) 2003 Wallis Software Solutions
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
// FITNESS FOR A PARTICULAR PURPOSE.
//
//===============================================================================

using System.Data;
using Agile.Common;
using Agile.Genie.Descriptors;
using GeneratorCustomization;

namespace Descriptors.GeneratorCustomization
{
    /// <summary>
    /// AuditDateColumnCollection
    /// </summary>
    public class AuditDateColumnCollection : AgileCollection
    {
        #region Preserved Region - Developer Hand Written Code

        private static AuditDateColumnCollection _allAuditDateColumns;

        /// <summary>
        /// Gets ALL of the columns listed in the excluded columns table.
        /// </summary>
        public static AuditDateColumnCollection All
        {
            get
            {
                if (_allAuditDateColumns == null)
                    LoadAuditDateColumns();
                return _allAuditDateColumns;
            }
        }

        /// <summary>
        /// Get all filtered columns for a specific table name.
        /// </summary>
        /// <param name="table">table to get all audit date columns for.</param>
        /// <returns></returns>
        public AuditDateColumnCollection FilteredBy(DatabaseTable table)
        {
            AuditDateColumnCollection filtered = Instantiate();
            foreach (AuditDateColumn auditDateColumn in this)
            {
                // look for a specific table name match (and database, though database may be ALL)
                if ((auditDateColumn.Table.ToLower() == table.Name.ToLower())
                    && ((auditDateColumn.Database.ToLower() == table.DatabaseName.ToLower()
                         || auditDateColumn.Database.ToUpper() == "ALL")))
                {
                    filtered.Add(auditDateColumn);
                }

                // Look for an ALL match (return it if there is a column with that name in the table.)
                if ((auditDateColumn.Table.ToUpper() == "ALL"
                     && table.Columns.FindColumn(auditDateColumn.ColumnName) != null)
                    &&
                    (auditDateColumn.Database.ToLower() == table.DatabaseName.ToLower() ||
                     auditDateColumn.Database.ToUpper() == "ALL"))
                {
                    filtered.Add(auditDateColumn);
                }
            }
            return filtered;
        }

        /// <summary>
        /// Gets all of the columns that have been specified as 
        /// audit date columns for the INSERT action.
        /// </summary>
        public AuditDateColumnCollection FilteredBy(AuditColumnAction action)
        {
            AuditDateColumnCollection filtered = Instantiate();
            foreach (AuditDateColumn auditColumn in this)
            {
                if (auditColumn.Action.Equals(action))
                    filtered.Add(auditColumn);
            }
            return filtered;
        }

        /// <summary>
        /// Checks if the given AuditDateTableColumn is in the collection.
        /// </summary>
        /// <param name="checkForThisColumn">auditDateTableColumn to look for in the collection.</param>
        /// <returns>True if the item is in the collection.</returns>
        public bool Contains(AuditDateColumn checkForThisColumn)
        {
            foreach (AuditDateColumn auditDateColumn in this)
            {
                if (auditDateColumn.ColumnName.ToLower().Equals(checkForThisColumn.ColumnName.ToLower())
                    && auditDateColumn.Table.ToLower().Equals(checkForThisColumn.Table.ToLower())
                    && auditDateColumn.Database.ToLower().Equals(checkForThisColumn.Database.ToLower())
                    && auditDateColumn.Action.Equals(checkForThisColumn.Action))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Checks if the given AuditDateTableColumn is in the collection.
        /// NOT case sensitive!
        /// </summary>
        /// <param name="name">The name of the column to look for in the collection.</param>
        /// <returns>True if the item is in the collection.</returns>
        public bool ContainsColumn(string name)
        {
            foreach (AuditDateColumn auditDateColumn in this)
            {
                if (auditDateColumn.ColumnName.ToLower().Equals(name.ToLower()))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Load the excluded columns details from the xml file.
        /// </summary>
        private static void LoadAuditDateColumns()
        {
            _allAuditDateColumns = Instantiate();
            DataRowCollection rows = GeneratorsData.GetDataRowsFor("AuditDateColumn");
            foreach (DataRow row in rows)
            {
                AuditDateColumn excluded = AuditDateColumn.Instantiate(row["Database"].ToString()
                                                                       , row["TableName"].ToString()
                                                                       , row["Column"].ToString()
                                                                       , row["Action"].ToString());
                _allAuditDateColumns.Add(excluded);
            }
        }

        #endregion // Preserved Region - Developer Hand Written Code

        #region Constructors and Factories

        /// <summary>
        /// Constructor
        /// </summary>
        internal AuditDateColumnCollection()
        {
        }

        /// <summary>
        /// Instantiate a new AuditDateColumnCollection
        /// </summary>
        public static AuditDateColumnCollection Instantiate()
        {
            return new AuditDateColumnCollection();
        }

        #endregion

        #region Strongly Typed IList Implementations

        /// <summary>
        /// Returns the AuditDateColumn that is at the given index in the collection.
        /// </summary>
        public AuditDateColumn this[int index]
        {
            get { return InnerList[index] as AuditDateColumn; }
        }

        /// <summary>
        /// Add a new AuditDateColumn to the collection
        /// </summary>
        /// <param name="auditDateColumn">auditDateColumn to add to the collection.</param>
        public void Add(AuditDateColumn auditDateColumn)
        {
            if (Contains(auditDateColumn))
            {
                string message =
                    string.Format("Tried adding a AuditDateColumn to the collection but it is already in it.");
                throw new AgileCommonException(message);
            }
            List.Add(auditDateColumn);
        }

        /// <summary>
        /// Remove a AuditDateColumn from the collection
        /// </summary>
        /// <param name="auditDateColumn">auditDateColumn to remove from the collection.</param>
        public void Remove(AuditDateColumn auditDateColumn)
        {
            InnerList.Remove(auditDateColumn);
        }

        /// <summary>
        /// Searches for the specified AuditDateColumn and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="auditDateColumn">auditDateColumn to get the index of from the collection.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(AuditDateColumn auditDateColumn)
        {
            return InnerList.IndexOf(auditDateColumn);
        }

        /// <summary>
        /// Searches for the specified AuditDateColumn and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="auditDateColumn">auditDateColumn to get the index of from the collection.</param>
        /// <param name="startIndex">The zero-based starting index of the search.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(AuditDateColumn auditDateColumn, int startIndex)
        {
            return InnerList.IndexOf(auditDateColumn, startIndex);
        }

        /// <summary>
        /// Searches for the specified AuditDateColumn and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="auditDateColumn">auditDateColumn to get the index of from the collection.</param>
        /// <param name="startIndex">The zero-based starting index of the search.</param>
        /// <param name="count">The number of elements in the section to search.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(AuditDateColumn auditDateColumn, int startIndex, int count)
        {
            return InnerList.IndexOf(auditDateColumn, startIndex, count);
        }

        /// <summary>
        /// Inserts the AuditDateColumn into the collection at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which value should be inserted.</param>
        /// <param name="auditDateColumn">auditDateColumn to insert into the collection.</param>
        public void Insert(int index, AuditDateColumn auditDateColumn)
        {
            InnerList.Insert(index, auditDateColumn);
        }

        /// <summary>
        /// Copies a range of elements from the collection of AuditDateColumn's to a compatible
        /// one-dimensional System.Array, starting at the specified index of the target array.
        /// </summary>
        /// <param name="auditDateColumns">The one-dimensional System.Array that is the destination of the elements copied from the collection. The System.Array must have zero-based indexing.</param>
        /// <param name="index">The zero-based index at which copying begins.</param>
        public void CopyTo(AuditDateColumn[] auditDateColumns, int index)
        {
            List.CopyTo(auditDateColumns, index);
        }

        #endregion
    }
}